#ifndef NETWORKMESSAGE_H
#define NETWORKMESSAGE_H

#include "NetworkDefinitions.h"

#pragma pack(push)
#pragma pack(1)

struct NetworkHeader
{
	char messageType;
	unsigned char sequenceNumber;

	NetworkHeader() : messageType(MSG_UNRELIABLE), sequenceNumber(0){}
};

#pragma pack(pop)

class NetworkMessage
{
private:
	unsigned char data[NET_MAX_DATA];
    int	currSize;
    int	readCount;

    unsigned char* GetSpace(int _size);

public:
	NetworkMessage();
	~NetworkMessage();
	NetworkMessage(const NetworkMessage& _NetMsg);
	NetworkMessage& operator=(const NetworkMessage& _NetMsg);

    void Clear();

	void SetBufferSize(int _size)		{currSize = _size;}
	void SetReadCount(int _readCount)	{readCount = _readCount;}
	int GetCurrentBufferSize() const	{return currSize;}
	int GetMaxBufferSize() const		{return NET_MAX_DATA;}
	int GetReadCount() const			{return readCount;}
	unsigned char* GetData()			{return data;}

	void BeginReading()					{readCount = 0;}
	void BeginWriting()					{currSize = 0;}

    char ReadByte();
    short ReadShort();
	int ReadInt();
	float ReadFloat();
	char* ReadStringByLen(int _length);
	char* ReadUUID();
	void* ReadData(int _size);

    void WriteByte(char _byte);
    void WriteShort(short _num);
    void WriteInt(int _num);
    void WriteString(char *_str);
	void WriteFloat(float _num);
    void WriteData(const void *_data, int _size);
};

#endif